package com.ymatou.iapi.livebuyer.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.ClearReplayDataBean;
import com.ymatou.iapi.livebuyer.service.ClearReplayDataCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.livevideo.parameter.RecLiveNotifyBean;
import com.ymatou.livevideo.parameter.ReplayNotifyBean;
import com.ymatou.livevideo.service.ReplayNotifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*定期清除回播数据
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ClearReplayData{
	private static ClearReplayDataBean clearreplaydataBean;
	private static ClearReplayDataCall clearreplaydataCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("定期清除回播数据");
	}

	@Before
	public void caseUp() {
		clearreplaydataBean=new ClearReplayDataBean();
		clearreplaydataCall=new ClearReplayDataCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(clearreplaydataCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearReplayData_001() {
		Logger.start(true,"定期清除回播数据");
		try {
			//把直播结束时间距离今天超过60天的回播地址（HistoryPlayUrl）清空
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			ReplayNotifyBean replaynotifyBean=new ReplayNotifyBean();
			ReplayNotifyCall replaynotifyCall=new ReplayNotifyCall();
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();	
			LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
			String histplayurl1=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getHistoryPlayUrl();
			Logger.verifyNotNull(histplayurl1, "验证histplayurl");
			//更新结束时间为50天之前
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextDay(-100), YMTDateUtil.getBeforeOrNextDay(-61),YMTDateUtil.getBeforeOrNextMunite(-61), liveroom.getId());
			clearreplaydataBean.setAppId("AutoTest");
			clearreplaydataCall.setData(clearreplaydataBean);
			clearreplaydataCall.callService();			
			Logger.verifyEquals("ok", clearreplaydataCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			String histplayurl2=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getHistoryPlayUrl();
			Logger.verifyEquals(null, histplayurl2, "验证histplayurl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearReplayData_002() {
		Logger.start(true,"定期清除回播数据15天内的不清除");
		try {
			//把直播结束时间距离今天超过60天的回播地址（HistoryPlayUrl）清空
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			ReplayNotifyBean replaynotifyBean=new ReplayNotifyBean();
			ReplayNotifyCall replaynotifyCall=new ReplayNotifyCall();
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();	
			LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
			String histplayurl1=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getHistoryPlayUrl();
			Logger.verifyNotNull(histplayurl1, "验证histplayurl");
			//更新结束时间为44天之前
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextDay(-100), YMTDateUtil.getBeforeOrNextDay(-59),YMTDateUtil.getBeforeOrNextMunite(-59), liveroom.getId());
			clearreplaydataBean.setAppId("AutoTest");
			clearreplaydataCall.setData(clearreplaydataBean);
			clearreplaydataCall.callService();			
			Logger.verifyEquals("ok", clearreplaydataCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			String histplayurl2=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getHistoryPlayUrl();
			Logger.verifyNotNull(histplayurl2, "验证histplayurl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ClearReplayData_003() {
		Logger.start(true,"定期清除回播数据-清除3个月前的groupid");
		try {
			Integer userid = 21158951;
			String uname = "sstest2";
			CreateSellerLiveBean createsellerliveBean = LiveRoomCallService.initOnlineCreatesellerliveBean(userid, uname);
			LiveRoom liveroom = LiveRoomCallService.CreateSellerLive(createsellerliveBean);
			LiveRoomCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomCallService.LiveNotify(recivenotifyBean);
			ReplayNotifyBean replaynotifyBean=new ReplayNotifyBean();
			ReplayNotifyCall replaynotifyCall=new ReplayNotifyCall();
			replaynotifyBean = LiveRoomCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();	
			LiveRoomWapper liveRoomWapper = new LiveRoomWapper();
			String histplayurl1=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getHistoryPlayUrl();
			Logger.verifyNotNull(histplayurl1, "验证histplayurl");
			//更新结束时间为100天之前
			liveRoomWapper.updateLiveRoomTime(YMTDateUtil.getBeforeOrNextDay(-110), YMTDateUtil.getBeforeOrNextDay(-100),YMTDateUtil.getBeforeOrNextMunite(-61), liveroom.getId());
			clearreplaydataBean.setAppId("AutoTest");
			clearreplaydataCall.setData(clearreplaydataBean);
			clearreplaydataCall.callService();			
			Logger.verifyEquals("ok", clearreplaydataCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			String gid=liveRoomWapper.selectLiveRoomById( liveroom.getId()).getGroupId();
			Logger.verifyEquals(null, gid, "验证groupid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}